package com.unhz.taigu.interface_controllers.logistics;

import com.unhz.generator.pojo.DeliveryInfo;
import com.unhz.generator.pojo.DeliveryOrder;
import com.unhz.generator.pojo.Logistics;
import com.unhz.generator.utils.EmptyUtil;
import com.unhz.generator.utils.JsonResult;
import com.unhz.taigu.service.AreaDictService;
import com.unhz.taigu.service.DeliveryInfoService;
import com.unhz.taigu.service.DeliveryOrderService;
import com.unhz.taigu.service.LogisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * @Author: 沈佳庆
 * @Description: 物流
 * @Date: Created in 下午 4:39 2018/3/3 0003
 * @Modified By: V1.0.0
 */
@RestController
@RequestMapping("/IIogistics")
public class IIogisticsController {

    @Autowired
    private LogisticsService logisticsService;

    @Autowired
    private DeliveryOrderService deliveryOrderService;

    @Autowired
    private DeliveryInfoService deliveryInfoService;

    @Autowired
    private AreaDictService areaDictService;

    /**
     * 查询物流信息
     * @param model
     * @param deliveryId
     * @return
     */
    @RequestMapping("/selectIogistics")
    public JsonResult selectIogistics(Model model, @RequestParam(value = "deliveryId",required = false) Integer deliveryId){
        DeliveryOrder deliveryOrder = deliveryOrderService.findDeliveryOrder(Long.valueOf(deliveryId));
        List<DeliveryInfo> deliveryInfoList = deliveryInfoService.selectByDeliveryOrderId(Long.valueOf(deliveryId));
        List<Logistics> logistics = logisticsService.selectByDeliveryId(deliveryId);
        model.addAttribute("logistics",logistics);
        model.addAttribute("deliveryOrder",deliveryOrder);
        model.addAttribute("deliveryInfoList",deliveryInfoList);
        model.addAttribute("areaDict",areaDictService.selectAreaDictAll());
        if(EmptyUtil.isEmpty(logistics)){
            return JsonResult.failure("无物流信息!");
        }
        return JsonResult.success("查询物流信息成功!",model);
    }
}
